<?php

namespace app\controller\tools;


use app\service\Dir;


class Test extends Base
{
	
	// 测试
	
	/**
	 * 1、设置
	 * 2、获取
	 */
	
	// index
	// http://www.light.com/tools/Test/index
	public function index()
	{
		//echo mt_rand();  // 666349795
		$file = 'xiaohua/'.date('Y/Ym/d/Ymd').microtime(true).mt_rand().'.jpg';  // 61
		$file = 'xiaohua/'.date('Y/Ym/d/').microtime(true).mt_rand().'.jpg';  // 51
		$file = 'xiaohua/'.date('Y/Ym/d/').uniqid().mt_rand().'.jpg';  // 50
		$data = ['file' => $file, 'len' => strlen($file), 'len2' => strlen(uniqid().mt_rand())];
		
		return $this->success($data);
	}
	
	// 修改文件名的后缀
	//  \{:.*?\}
	//  \{\$.*?\}
	public function change()
	{
		// 文件夹
		$path = $this->app->getRootPath();
		$path .= 'blade'.DIRECTORY_SEPARATOR.'wap'.DIRECTORY_SEPARATOR;
		
		// 阅读文件夹
		$dir   = new Dir();
		$files = $dir->read($path, true);
		
		// 执行修改
		foreach($files as $_file){
			/*$ext = substr($_file, -10);
			if($ext == '.blade.php'){
				$_new = substr($_file, 0, -10).'.php';
				rename($_file, $_new);
			}*/
			
			/*$ext = substr($_file, -16);
			if($ext == '.blade.blade.php'){
				$_new = substr($_file, 0, -16).'.blade.php';
				rename($_file, $_new);
			}*/
			
			/*$ext = pathinfo($_file, PATHINFO_EXTENSION);
			if($ext == 'php'){
				$_new = substr($_file, 0, -4).'.blade.php';
				rename($_file, $_new);
			}*/
			
			$ext = pathinfo($_file, PATHINFO_EXTENSION);
			if($ext == 'html'){
				$_new = substr($_file, 0, -5).'.blade.php';
				rename($_file, $_new);
			}
		}
		
		//rename('D:\phpSite\tp\light\view\addIp.html', 'D:\phpSite\tp\light\view\addIp.php');
		var_dump($files);
		
		return $this->success();
	}
	
}

